import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // isAuthenticated:false, // 登录状态
    navShow : true,    // 底部菜单是否显示
    fullLoading:true,  // 全屏加载中
    tempInvoiceInputList:[],//正在填写的发票信息列表
    billTypeLists:[],  // 发票类型
    swiperPage:-1      // 编辑完以后跳转到的swiper页码
  },
  getters: {
  },
  mutations: {
    // // 登录状态
    // setisAuthenticated(state,type){
    //   state.isAuthenticated = type;
    // },
    
    // 发票类型
    setBillTypeLists(state,arr){
      state.billTypeLists = arr;
    },
    // 设置底部菜单状态
    setNavShow(state,type){
      state.navShow = type;
    },
    // 设置loading状态
    setFullLoading(state, type){
      state.fullLoading = type;
    },
    setTempInvoiceInputList(state, arr){
      arr.map(v=>{
        // 首先判断是否存在总额
        if(Array.isArray(v.records) && v.records.filter(w=>['fare','totalAmount','Amount'].includes(w.key)).length <= 0){
          // 如果没有则添加一条
          v.records.unshift({
            children :null,
            key :"fare",
            label :"总额",
            required :null,
            type :"1",
            value :"0",
          })
        }
      })
      state.tempInvoiceInputList = arr
    },
    setSwiperPage(state, num){
      state.swiperPage = num;
    }
  },
  modules: {
  }
})
